package com.synnex.mobile.servier.web.resource.controller;

import com.synnex.mobile.generic.core.exception.SystemException;
import com.synnex.mobile.generic.core.util.FileUtil;
import com.synnex.mobile.generic.core.util.FormatUtil;
import com.synnex.mobile.generic.core.util.LinkedMultiValueMap;
import com.synnex.mobile.generic.core.util.MultiValueMap;
import com.synnex.mobile.generic.web.multipart.MultipartFile;
import com.synnex.mobile.generic.web.multipart.MultipartRequest;
import com.synnex.mobile.servier.core.contact.service.ContactService;
import com.synnex.mobile.servier.core.resource.service.ResourceService;
import com.synnex.mobile.servier.web.common.controller.AbstractController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author kerry
 */
public abstract class AbstractResourceController extends AbstractController {
    protected ResourceService resourceService;

    public void setResourceService(ResourceService resourceService) {
        this.resourceService = resourceService;
    }

    //    protected MultiValueMap<String, String> uploadFilesToFtp(HttpServletRequest request, String ftpPath, String name,String fileName) {
//    protected MultiValueMap<String, String> uploadFilesToFtp(HttpServletRequest request, String name,String fileName) {
//        MultiValueMap<String, String> results = new LinkedMultiValueMap<String, String>(1);
//        MultipartRequest multipartRequest = (MultipartRequest) request;
//        List<MultipartFile> files = multipartRequest.getFiles(name);
//        for (MultipartFile multipartFile : files) {
//            try {
//                if (multipartFile.isEmpty()) {
//                    continue;
//                }
//                String fileSufix = FileUtil.getFileSuffix(multipartFile.getOriginalFilename());
//                String data = "";
//                if(null == fileName){
////                    data = FormatUtil.formatDate("yyyyMMddhhmmssSS", new Date());
//                    data = UUID.randomUUID().toString().replaceAll("-","");
//                }else{
//                    data = fileName;
//                }
//
//                FileUtil.ftpUpload(getConfig().getFtpHost(), getConfig().getFtpPort(),
//                        getConfig().getFtpUserName(), getConfig().getFtpPwd(),
//                        getConfig().getFtpUploadPath(), data+"."+fileSufix, multipartFile.getInputStream());
//
//                results.add(name, data+"."+fileSufix);
//            } catch (Exception ex) {
//                throw new SystemException("File [" + multipartFile.getOriginalFilename() + "] can't be upload.");
//            }
//        }
//        return results;
//    }

}
